//package com.wnxy.admin.listener;
//
//import com.rabbitmq.client.Channel;
//import org.springframework.amqp.rabbit.annotation.RabbitHandler;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.amqp.support.AmqpHeaders;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.mail.SimpleMailMessage;
//import org.springframework.mail.javamail.JavaMailSender;
//import org.springframework.messaging.handler.annotation.Header;
//import org.springframework.stereotype.Component;
//
//import java.io.IOException;
//import java.util.Map;
//import java.util.concurrent.TimeUnit;
//
//@Component
//@RabbitListener(queues = {"email_queue"})
//public class EmailListener {
//    private final JavaMailSender javaMailSender;
//    private final RedisTemplate redisTemplate;
//
//    public EmailListener(JavaMailSender javaMailSender, RedisTemplate redisTemplate) {
//        this.javaMailSender = javaMailSender;
//        this.redisTemplate = redisTemplate;
//    }
//
//    @RabbitHandler
//    public void handlerMsg(Map<String, String> msg, Channel channel,@Header(AmqpHeaders.DELIVERY_TAG) Long deliveryTag) throws IOException {
//        try {
//            String from = msg.get("from");
//            String to = msg.get("to");
//            String subject = msg.get("subject");
//            String code = msg.get("code");
//            /*封装短信消息对象*/
//            SimpleMailMessage smm = new SimpleMailMessage();
//            smm.setFrom(from);
//            smm.setTo(to);
//            smm.setSubject(subject);
//            smm.setText("超级老八: 验证码[" + code + "],有效期5分钟，请尽快使用");
//            javaMailSender.send(smm);
//            redisTemplate.opsForValue().set(to, code, 5, TimeUnit.MINUTES);
//            channel.basicAck(deliveryTag, false);
//        } catch (IOException e) {
//            channel.basicNack(deliveryTag, true, false);
//            throw new RuntimeException(e);
//        }
//
//    }
//
//}
